package cn.com.csg.smartenergy.modules.biz.iot.controller;

import cn.com.csg.smartenergy.modules.biz.entity.IotDeviceEntity;
import cn.com.csg.smartenergy.modules.biz.iot.entity.IotParseTemplateEntity;
import cn.com.csg.smartenergy.modules.biz.iot.service.IotParseTemplateService;
import cn.com.csg.smartenergy.util.OperResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/iot/parse")
public class IotParseTemplateController {
    @Autowired
    private IotParseTemplateService iotParseTemplateService;

    /**
     * ??
     */
    @ResponseBody
    @RequestMapping("/list")
    public OperResult list(@RequestParam(required = false) IotParseTemplateEntity params){
        List list = iotParseTemplateService.getBaseMapper().selectList(new QueryWrapper<IotParseTemplateEntity>().setEntity(params));
        return OperResult.ok().put("data", list);
    }

    /**
     * ??
     */
    @RequestMapping("/info/{id}")
    public OperResult info(@PathVariable("id") Long id){
        IotParseTemplateEntity iotParseTemplateEntity =  iotParseTemplateService.getById(id);
        return OperResult.ok().put("data", iotParseTemplateEntity);
    }

    /**
     * ??
     */
    @RequestMapping("/save")
    public OperResult save(@RequestBody IotParseTemplateEntity data){
        iotParseTemplateService.save(data);
        return OperResult.ok();
    }

    /**
     * ??
     */
    @RequestMapping("/update")
    public OperResult update(@RequestBody IotParseTemplateEntity iotParseTemplate){
        iotParseTemplate.setUpdateTime(new Date());
        iotParseTemplateService.updateById(iotParseTemplate);
        return OperResult.ok();
    }

    /**
     * ??
     */
    @RequestMapping("/delete")
    public OperResult delete(@RequestBody Long[] ids){
        iotParseTemplateService.removeByIds(Arrays.asList(ids));
        return OperResult.ok();
    }


}
